<template>
  <div>
    <Nav></Nav>
    <HeadNav></HeadNav>
    <div class="box_title">
      <p>
        {{ this.booklist.length }}条结果 |
        <span style="color: #9d232c">{{this.categoriesName}}</span>
      </p>
    </div>
    <div class="box">
      <div class="book_sort">
        <div class="tab">
          <div class="tab_head">分类</div>
          <div v-for="sort in this.fenlei" class="tab_list" :key="sort.categoriesId">
            <router-link :to="{ path: '/book_list',query: { id:sort.categoriesId,name:sort.classname}}"  @click.native="goAddpage"
               ><div style="color: black;width: 100%" >
                {{ sort.classname}}
              </div></router-link
            >
          </div>
        </div>
      </div>
      <div class="book_info1">
        <div class="book_content1" v-for="book in tableData" :key="book.isbn">
          <router-link :to="{ path: '/book', query: { id: book.isbn } }">
            <div class="book_content_img">
              <el-image
                style="width: 82%; height: 150px;margin:5px 9%"
                :src="'https://images.weserv.nl/?url=' + book.img"
                fit="fill"
              ></el-image>
            </div>
         
          <div class="book_content_info1">
            <div class="book_name1">{{ book.title }}</div>
            <div class="book_list_content1">作者: {{ book.author }}</div>
            <div class="book_list_content1">ISBN: {{ book.isbn }}</div>
            <div class="book_list_content1">出版社: {{ book.bookPress }}</div>
            <div class="book_list_content1">
              出版时间: {{ book.createTime }}}
            </div>
            <div class="book_list_content1">原价: {{ book.price }}</div>
            <div class="book_list_content1">售价: {{ book.price }}</div>
            <div>
              <el-button
                type="primary"
                icon="el-icon-shopping-cart-2"
                class="cartBtn"
                >加入购物车</el-button
              >
              <el-button class="plainBtn" plain>立即购买</el-button>
            </div>
            
          </div>
          </router-link>
        </div> 
        <div
          class="block"
         
          style="float: right;padding: 0px 30px 10px"
        >
          <el-pagination
             @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="index"
        :page-sizes="[5,10, 20,50, 100]"
        :page-size="pageSize"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        pageNo=1
          >
          </el-pagination>
        </div>
        <!-- <div
         
          style="width:100%;height: 50px;line-height: 50px;padding: 0px 20px"
        >
          不好意思，此分类暂时还没有图书......
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
import Nav from "../../com/components/Common/Nav";
import HeadNav from "../../com/components/Common/HeadNav";
import axios from "axios";
export default {
  components: { Nav, HeadNav },
  data() {
    return {
       fenlei:[],
      booklist:[],
      categoriesId: "",
      categoriesName:'',
      pageSize: 10,
      totalSize: null,
      index: 1,
      tableData: [],//el-table  绑定的数据
    };
  },
  methods: {
    getbook() {
      //获取分类图书列表
      axios
        .get("http://localhost:8081/fl-book/getCategoriesBooks", {
          params: {
            categoriesId: this.categoriesId,
          },
        })
        .then((res) => {
          

          this.booklist = res.data.data;
            console.log(this.booklist);
           this.getList();
              
        });
       
    },
    //获取分类数据
      good_fenlei(){
        axios.get("http://localhost:8081/fl-categories/getAllCategories",{
          
        }).then((res)=>{
        
          this.fenlei=res.data.data;
          console.log(this.fenlei);
        })
      },
    getList() {
      this.tableData = this.booklist.filter(            //分页函数 filter筛选数组
        (item, index) =>
          index < this.index * this.pageSize &&
          index >= this.pageSize * (this.index - 1)
      );
      this.totalSize = this.booklist.length;
    },
      handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.index = val;
      this.getList();
    },
    goAddpage(){        //路由在页面不跳转情况刷新
        this.$router.go(0);
     
    }
     
  },
  created() {
      this.categoriesId=this.$route.query.id;       //接收分类列表返回的参数
      this.categoriesName=this.$route.query.name;
      this.getbook();
        this.good_fenlei();
  },

  
};
</script>

<style>
.content {
  background-color: #ffffff;
}
.box_title {
  margin: 10px auto;
  width: 1240px;
  color: #545c64;
  padding: 5px 10px;
}
.box {
  margin: 10px auto;
  width: 1240px;
}
.book_sort {
  margin: 10px 10px;
  width: 200px;
  float: left;
  border-right: 1px #f3f0e9 solid;
}

.book_info1 {
  margin: 10px 10px;
  width: 1000px;
  float: right;
  background-color: #f7f7f6;
}
.tab {
  width: 100%;
}
.tab_head {
  padding-left: 5px;
  width: 100%;
  height: 40px;
  line-height: 40px;
  background-color: #f3f0e9;
  margin: 1px 0px;
}
.tab_list {
  padding-left: 5px;
  width: 100%;
  height: 40px;
  line-height: 40px;
  background-color: #ffffff;
  margin: 1px 0px;
}
.tab_list:hover {
  background-color: #a0a9b1;
}

.book_content1 {
  border: 1px #f3f0e9 solid;
  padding: 5px;
  margin: 10px auto;
  width: 940px;
  height: 190px;
  max-height: 240px;
  line-height: 35px;
  border: 1px solid #cacaca;
  padding: 15px;
}
.book_content1:hover {
  background-color: white;
}

.book_content_img {
  float: left;
  width: 150px;
  height: 160px;
  /*border: 1px solid black;*/
}
.book_content_info1 {
  float: right;
  width: 740px;
  height: 160px;
  color: black;
  /*border: 1px solid black;*/
}

.book_name1 {
  margin: 5px auto;
  width: 740px;
  line-height: 30px;
  font-size: 18px;
  color: #9d232c;
  overflow: hidden;
}

.book_list_content1 {
  width: 32%;
  display: inline-block;
  height: 20px;
  overflow: hidden;
  line-height: 18px;
  font-size: 14px;
}

.plainBtn {
  width: 100px;
  color: #9d232c;
  background-color: #f3f0e9;
  border: 1px #f3f0e9 solid;
  float: right;
  margin: 0px 5px;
  font-size: 14px;
}
.plainBtn:hover {
  background-color: white;
  color: #9d232c;
  border: 1px #b2bac2 solid;
}
.cartBtn {
  width: 140px;
  background-color: #9d232c;
  border: 1px #9d232c solid;
  float: right;
  margin: 0px 5px;
  font-size: 14px;
}
.cartBtn:hover {
  background-color: #f52b21;
}
</style>
